#
# Download, configure, and install Python v3.8.18
#
# Assumptions:
#
# - Dependencies for building Python3 are met (system packages etc.)
# - Commands are executed with sufficient privileges (sudo/root)
#
# Download and extract
pushd /tmp
wget https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tgz
tar xzf Python-3.8.18.tgz
popd
mv /tmp/Python-3.8.18 toolbox/third-party/python3/src

# Configure and build
pushd toolbox/third-party/python3/src
./configure --enable-optimizations --enable-shared
make altinstall -j $(nproc)
popd

# Setup handling of python3
ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
hash -d python3 || true

# Avoid error with "libpython*so.1.0: cannot open shared object file: No such file or directory"
ldconfig /usr/local/lib
